package cn.wen.yinxiu.system.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.wen.yinxiu.common.convention.result.Results;
import cn.wen.yinxiu.common.to.system.NoticeTO;
import cn.wen.yinxiu.system.vo.NoticeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yinxiu.system.entity.NoticesEntity;
import cn.wen.yinxiu.system.service.NoticesService;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.convention.result.ResultEntity;

/**
 *
 * @ClassName: NoticesController
 * @Author 小飞
 * @Email coderwen22@163.com
 * @Date 2023-05-22 09:46:50
 * @Description: 的Controller层
 */
@RestController
@RequestMapping("/web")
public class NoticesController {

    @Autowired
    private NoticesService noticesService;

    @PostMapping("/api/system/notice/add")
    public ResultEntity<NoticeTO> addNotice(@RequestBody NoticeTO notice) {
        NoticeTO res = noticesService.saveNoticeByTo(notice);
        return Results.success(res);
    }

    @GetMapping("/api/system/notice/list")
    public ResultEntity<List<NoticeVO>> addNotice(@RequestParam("userId") Long userId,
                                                  @RequestParam("page") Integer page) {
        List<NoticeVO> res = noticesService.selectNoticeList(userId, page);
        return Results.success(res);
    }

    @GetMapping("/api/system/notice/delete")
    public ResultEntity deleteNotice(@RequestParam("noticeId") Long noticeId) {
        boolean res = noticesService.deleteNoticeById(noticeId);
        if (!res) return Results.failure();
        return Results.success();
    }

}
